package socket;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Client {
    private Socket socket;
    public  Client(){
        System.out.println("正在连接服务器");
        try {
            socket=new Socket("localhost",8488);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("与服务器连接成功");

    }
    public void start(){
        try {
            OutputStream sis=socket.getOutputStream();
            OutputStreamWriter sos=new OutputStreamWriter(sis, StandardCharsets.UTF_8);
            BufferedWriter ses=new BufferedWriter(sos);
            PrintWriter sws=new PrintWriter(ses,true);
            sws.println("打死你给龟孙");

            Scanner scan=new Scanner(System.in);
            while(true){
                String line= scan.nextLine();
                if ("exit".equals(line)){
                    break;
                }
                sws.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }


    public static void main(String[] args) {
        Client client=new Client();
        client.start();
    }
}